//
//  LetterListViewController.m
//  DirectProDuct
//
//  Created by hl on 16/1/22.
//  Copyright (c) 2016年 ping. All rights reserved.
//

#import "LetterListViewController.h"
#import "LetterListCell.h"
#import "LetterDetailViewController.h"
@interface LetterListViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
    RWScrollView *listTable;
}

@end

@implementation LetterListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawNavWithTitle:self.titleStr];
    [self drawBackButton];
    [self drawView];
    [self requestData];
    // Do any additional setup after loading the view.
}
-(void)drawView{
    listTable = [[RWScrollView alloc] initWithFrame:CGRectMake(0,78+5, KScreenWidth, KScreenHeight - 69 - 14) style:UITableViewStylePlain];
    listTable.delegate = self;
    listTable.dataSource = self;
    listTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:listTable];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"cell";
    LetterListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[LetterListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.peopleLab.text = @"张三";
    cell.topicLab.text = @"主题";
    cell.timeLab.text = @"2016-01-22";
    cell.sizeLab.text = @"15k";
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 25 * _kscH)];
    view.backgroundColor = [UIColor grayColor];
    float labW = (KScreenWidth - 50 * _kscW)/4;
    NSMutableArray *titleArr = [[NSMutableArray alloc] init];
    if ([self.titleStr isEqual:@"未读信件"] == 1 || [self.titleStr isEqual:@"收件箱"] == 1) {
        [titleArr addObject:@"发件人"];
    }else{
        [titleArr addObject:@"收件人"];
    }
    [titleArr addObject:@"主 题"];
    [titleArr addObject:@"时 间"];
    [titleArr addObject:@"大 小"];
    for (int i = 0; i<4; i++) {
        UILabel *tipLab = [[UILabel alloc] initWithFrame:CGRectMake(labW * i, 0, labW, view.height)];
        tipLab.textColor = [UIColor whiteColor];
        tipLab.font = [UIFont systemFontOfSize:13.0];
        tipLab.text = [titleArr objectAtIndex:i];
        tipLab.textAlignment = NSTextAlignmentCenter;
        [view addSubview:tipLab];
    }
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 30 * _kscH;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 25 * _kscH;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    LetterDetailViewController *detail = [[LetterDetailViewController alloc] init];
    detail.titleStr = self.titleStr;
    [self.navigationController pushViewController:detail animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
